using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace YYJ
{
    public partial class DataBaseConnector : Form
    {
        public DataBaseConnector()
        {
            InitializeComponent();
            txtConn.Text = System.Configuration.ConfigurationManager.ConnectionStrings[ "YYJ" ].ConnectionString; 
            txtSql.Text = "select count(*) from board";
        }
        
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string cmdText = txtSql.Text;
                using (SqlDataAdapter adapter = new SqlDataAdapter(cmdText, txtConn.Text))
                {

                    adapter.SelectCommand.CommandTimeout = 60;
                    DataTable dt = new DataTable();

                    adapter.Fill(dt);
                    MessageBox.Show(dt.Rows.Count.ToString());
                    
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("failed to connect." + ex.Message);
            }

        }
    }
}